import unittest
from XTestRunner import HTMLTestRunner

def get_student_info(student_id):
    students = {
        1001: {"name": "方鸿新", "age": 21, "sex": "男"},
        1002: {"name": "苏文芷", "age": 21, "sex": "女"},
        1003: {"name": "唐晓芙", "age": 17, "sex": "女"},
        1004: {"name": "赵辛媚", "age": 16, "sex": "女"}
    }
    return students.get(student_id, "The student ID does not exist.")

class TestGetStudentInfo(unittest.TestCase):
    def student_info_func(self,student_id,expect):
        self.assertEqual(expect, get_student_info(student_id), "断言失败")

    def test_case_1(self):
        self.student_info_func(1001,{"name": "方鸿新", "age": 21, "sex": "男"})

    def test_case_2(self):
        self.student_info_func(1007, "The student ID does not exist.")

    def test_fail_1(self):
        self.student_info_func(1001,{"name": "赵辛媚", "age": 16, "sex": "女"})

    def test_error_1(self):
        self.student_info_func(None)

    @unittest.skip
    def test_skip_1(self):
        self.student_info_func(1007,"The student ID does not exist.")

if __name__ == '__main__':
    suit = unittest.TestLoader().loadTestsFromTestCase(TestGetStudentInfo)
    with open('./report.html', 'wb') as fp:
        runner = HTMLTestRunner(
            stream=fp,
            title='XTestRunner样例测试报告',
            description='测试用例执行情况',
            language='zh_CN',
            rerun=1,
        )
        runner.run(suit)
